﻿using System;

// XNA lib
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;

//Oak Engine Lib
using OakEngine.GameState;
using OakEngine.Input;
using Microsoft.Xna.Framework.Input;

namespace MainJumpFleet.GameStates
{
    public partial class PrototypePlaygroundScreenState : OAK_IGameState
    {
        private void LoadAssets()
        {
            #region LOAD AUDIO
            // loads the background music
            backgroundMusicSong = CGame.CGame.GetInstance().Content.Load<Song>(@"backgroundMusic\beacon_of_hope_strings");
            isBackgroundMusicPaused = false;
            #endregion

            #region LOAD TEXTURES
            starfieldBackgroundTexture = CGame.CGame.GetInstance().Content.Load<Texture2D>(@"textures\starfield_1024x1024");
            // starfieldBackgroundTexture = CGame.CGame.GetInstance().Content.Load<Texture2D>(@"textures\starfield_1024x1024_outline");

            playerShipTexture = CGame.CGame.GetInstance().Content.Load<Texture2D>(@"textures\ship2_77x128");

            bulletTexture = CGame.CGame.GetInstance().Content.Load<Texture2D>(@"textures\missile_6x14");

            enemyShipFighterTexture = CGame.CGame.GetInstance().Content.Load<Texture2D>(@"textures\ship4_86x128");

            #endregion

            #region LOAD SPRITE TEMPLATES
            // creates the static sprite template for the starfield background 
            spriteManager.CreateStaticSpriteTemplate("StarfieldBackground", starfieldBackgroundTexture, 0, 0, 1024, 1024, Color.White, 255, 0, JumpFleetGameLib.xSprite.RotationAnchorPoint.TopLeft, 1.0f, SpriteEffects.None, 1.0f);

            // creates the static sprite template for the player ship
            spriteManager.CreateStaticSpriteTemplate("PlayerShip", playerShipTexture, 0, 0, 77, 128, Color.White, 255, 0, JumpFleetGameLib.xSprite.RotationAnchorPoint.Center, 1.0f, SpriteEffects.None, 0.3f);

            // creates the static sprite template for the bullet
            spriteManager.CreateStaticSpriteTemplate("Bullet", bulletTexture, 0, 0, 6, 14, Color.White, 255, 0, JumpFleetGameLib.xSprite.RotationAnchorPoint.Center, 2.0f, SpriteEffects.None, 0.301f);

            // creates the static sprite templates for the enemy ships
            spriteManager.CreateStaticSpriteTemplate("EnemyFighter", enemyShipFighterTexture, 0, 0, 86, 128, Color.White, 255, 0, JumpFleetGameLib.xSprite.RotationAnchorPoint.Center, 0.5f, SpriteEffects.None, 0.401f);

            #endregion

            #region LOAD SECTOR MAP
            prototypeSectorMap = new JumpFleetGameLib.xMap.SectorMap.SectorMap("Prototype", 1, 0, 1024, 1024, 3, 3);

            // sets the background layer's tag
            prototypeSectorMap.BackgroundLayers[0].Tag = "StarfieldBackground";

            // sets up a starfield background tile to clone
            JumpFleetGameLib.xMap.SectorMap.StaticBackgroundTile starfieldBackgroundTile = new JumpFleetGameLib.xMap.SectorMap.StaticBackgroundTile(spriteManager, "StarfieldBackground", "StarfieldBackground", 1024, 1024, 1.0f);

            // fills the sector map with starfield background tiles
            for (int row = 0; row < prototypeSectorMap.BackgroundLayers[0].Tiles.GetLength(1); row++)
                for (int column = 0; column < prototypeSectorMap.BackgroundLayers[0].Tiles.GetLength(0); column++)
                {
                    prototypeSectorMap.BackgroundLayers[0].Tiles[column, row] = starfieldBackgroundTile.Clone();
                    prototypeSectorMap.BackgroundLayers[0].Tiles[column, row].Position = new Vector2(column * starfieldBackgroundTile.Width, row * starfieldBackgroundTile.Height);
                }

            // sets the drawing depth for the background layer
            prototypeSectorMap.BackgroundLayers[0].Depth = 0.999f;

            // sets the background layer to visible
            prototypeSectorMap.BackgroundLayers[0].Visible = true;

            // sets the starting position for the sector map
            prototypeSectorMap.CurrentStartingDrawPosition = new Vector2(0, 0);

            #endregion

            #region BACKGROUND MUSIC
            // starts playing the background music            
            MediaPlayer.Play(backgroundMusicSong);
            MediaPlayer.IsRepeating = true;
            #endregion
        }
    }
}
